package com.jwork.progress.controllers;

import com.jwork.progress.params.CommonResponse;
import com.jwork.progress.pojo.dto.job.JobCreateDTO;
import com.jwork.progress.service.job.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.quartz.*;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Api(tags = "任务")
@RestController
@RequestMapping("/jobs")
@RefreshScope
@RequiredArgsConstructor
public class JobController {
    private final JobService jobService;

    @ApiOperation(value = "添加")
    @PostMapping("/create")
    public CommonResponse createJob(@RequestBody JobCreateDTO dto) {
        return jobService.createJob(dto);
    }

    @ApiOperation(value = "暂停")
    @PostMapping("/pause/{group}/{name}")
    @ApiImplicitParams({@ApiImplicitParam(name = "group", value = "分组", required = true), @ApiImplicitParam(name =
            "name", value = "任务名", required = true)})
    public CommonResponse pauseJob(@PathVariable String group, @PathVariable String name) {
        return jobService.pauseJob(group, name);
    }

    @ApiOperation(value = "恢复")
    @PostMapping("/resume/{group}/{name}")
    @ApiImplicitParams({@ApiImplicitParam(name = "group", value = "分组", required = true), @ApiImplicitParam(name =
            "name", value = "任务名", required = true)})
    public CommonResponse resumeJob(@PathVariable String group, @PathVariable String name) {
        return jobService.resumeJob(group, name);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete/{group}/{name}")
    @ApiImplicitParams({@ApiImplicitParam(name = "group", value = "分组", required = true), @ApiImplicitParam(name =
            "name", value = "任务名", required = true)})
    public CommonResponse deleteJob(@PathVariable String group, @PathVariable String name) {
        return jobService.deleteJob(group, name);
    }
}
